package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	fmt.Println(gin.Version)
	// 1. 创建路由
	r := gin.Default()
	// 2. 绑定路由规则，执行的函数
	r.GET("/book/:id", GetBookDetailHandler)
	r.GET("/user", GetUserDetailHandler)
	r.GET("/bookAndUser/:id", GetBookAndUserDetailHandler)
	// 3. 监听的端口，默认在8000
	r.Run(":8000")
}

func GetBookDetailHandler(c *gin.Context) {
	bookId := c.Param("id")
	c.String(http.StatusOK, fmt.Sprintf("成功获取书籍详情：%s", bookId))

}

func GetUserDetailHandler(c *gin.Context) {
	username := c.Query("name")
	c.String(http.StatusOK, fmt.Sprintf("成功获取用户详情：%s", username))

}

func GetBookAndUserDetailHandler(c *gin.Context) {
	bookId := c.Param("id")
	username := c.Query("name")
	c.String(http.StatusOK, fmt.Sprintf("成功获取书籍和用户详情：%s,%s", bookId, username))

}
